CREATE PROCEDURE [dbo].[getserverlisthtml]
 -- Add the parameters for the stored procedure here
 @environment varchar(20)
AS
BEGIN

SELECT rtrim(ltrim(servername)) 
   from msdb.dbo.htmlreports where proddevstage=@environment

END
GO


CREATE PROCEDURE [dbo].[Getdeschtmlreports]
 -- Add the parameters for the stored procedure here
 @servername varchar(100)
AS
BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT description 
 from msdb.dbo.htmlreports where servername=@servername

END
GO


CREATE PROCEDURE [dbo].[GetThresholdhtmlreports]
 -- Add the parameters for the stored procedure here
 @servername sysname
AS
BEGIN

declare @dayname varchar(10)
declare @threshold int
--declare @servername sysname

/**
select
 @DayName =
   CASE (DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7
    WHEN 1 THEN 'Sunday'
    WHEN 2 THEN 'Monday'
    WHEN 3 THEN 'Tuesday'
    WHEN 4 THEN 'Wednesday'
    WHEN 5 THEN 'Thursday'
    WHEN 6 THEN 'Friday'
    WHEN 0 THEN 'Saturday'
end **/


if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 0)
 begin
  select @threshold = saturdaythreshold 
    from htmlreports 
    where servername=@servername
 end
if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 1)
 begin
  select @threshold = sundaythreshold 
   from htmlreports 
   where servername=@servername
 end
if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 2)
 begin
  select @threshold = mondaythreshold 
   from htmlreports 
   where servername=@servername
 end
if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 3)
 begin
  select @threshold = Tuesdaythreshold 
   from htmlreports 
   where servername=@servername
 end
if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 4)
 begin
  select @threshold = Wednesdaythreshold 
   from htmlreports 
   where servername=@servername
 end
if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 5)
 begin
  select @threshold = Thursdaythreshold 
   from htmlreports 
   where servername=@servername
 end
if (((DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7)= 6)
 begin
  select @threshold = Fridaythreshold 
   from htmlreports 
   where servername=@servername
 end

select @threshold

return @threshold
END
